import type { PlusColumn } from 'plus-pro-components'

import { ConditionInit } from '@fl/api/anjutong'

export type IRowV0 = {
    /**
     * 性别
     */
    gender?: string
    /**
     * 会员图片
     */
    headImage?: string
    /**
     * 会员等级
     */
    memberLevel?: string
    /**
     * 会员id
     */
    memberMetaId?: number
    /**
     * 会员标签列表
     */
    memberTagList?: Itag[]
    /**
     * 会员类型
     */
    memberType?: string
    /**
     * 会员电话
     */
    mobile?: string
    /**
     * 昵称
     */
    nickName?: string
    /**
     * 会员姓名
     */
    realName?: string
}
export type Itag = {
    /**
     * 标签id
     */
    id?: number
    /**
     * 标签名称
     */
    name?: string
}

type IMemberLevelVOList = {
    levelId: number
    levelName: string
}
type IMinType = {
    code: number
    name: string
}

const optTag = ref<any>([])
const optLevel = ref<any>([])
const optType = ref<any>([])
const optName = ref<any>([])

ConditionInit().then((res: any) => {
    const { booleanVOList, memberLevelVOList, memberTagVOList, memberTypeVOList } = res
    optTag.value = memberTagVOList.map((v: any) => {
        return {
            label: v.name,
            value: v.id,
        }
    })
    optLevel.value = memberLevelVOList.map((item: IMemberLevelVOList) => {
        return {
            label: item.levelName,
            value: item.levelId,
        }
    })
    optType.value = memberTypeVOList.map((item: IMinType) => {
        return {
            label: item.name,
            value: item.code,
        }
    })

    optName.value = booleanVOList.map((item: IMinType) => {
        return {
            label: item.name,
            value: item.code,
        }
    })
})

// 查询
export const searchColumns: PlusColumn[] = [
    {
        colProps: {
            span: 4,
        },
        hasLabel: false,
        label: '',
        options: [
            {
                label: '今日',
                value: 1,
            },
            {
                label: '昨日',
                value: 2,
            },
            {
                label: '最近七天',
                value: 3,
            },
            {
                label: '最近30天',
                value: 4,
            },
        ],
        prop: 'timeLimit',
        valueType: 'select',
    },
    {
        fieldProps: { multiple: true },
        label: '会员标签',
        options: optTag,
        prop: 'memberTagIdList',
        valueType: 'select',
    },
    {
        fieldProps: { multiple: true },
        label: '会员等级',
        options: optLevel,
        prop: 'memberLevelList',
        valueType: 'select',
    },
    {
        colProps: {
            span: 6,
        },
        label: '昵称',
        prop: 'nickName',
        valueType: 'copy',
    },
    {
        colProps: {
            span: 6,
        },
        label: '手机号',
        prop: 'mobile',
        valueType: 'copy',
    },
    {
        colProps: {
            span: 6,
        },
        label: '用户类型',
        options: optType,
        prop: 'memberType',
        valueType: 'select',
    },
    {
        colProps: {
            span: 6,
        },
        label: '实名认证',
        options: optName,
        prop: 'realNameAuthentication',
        valueType: 'select',
    },
    {
        colProps: {
            span: 6,
        },
        label: '姓名',
        prop: 'realName',
        valueType: 'copy',
    },
    {
        colProps: {
            span: 6,
        },
        label: '身份证',
        prop: 'idCardNo',
        valueType: 'copy',
    },
    {
        colProps: {
            span: 6,
        },
        label: '是否授权', // 0未授权，1已授权
        options: [
            {
                label: '否',
                value: '0',
            },
            {
                label: '是',
                value: '1',
            },
        ],
        prop: 'isAuthorizedPhone',
        valueType: 'select',
    },
] as const

// 修改积分
export const editIntegralColumns: PlusColumn[] = [
    {
        fieldProps: { disabled: true },
        label: '当前积分',
        prop: 'accumulatedPoints',
        valueType: 'copy',
    },
    {
        fieldProps: { precision: 0 },
        label: '数量',
        prop: 'operationPoints',
        valueType: 'input-number',
    },
    {
        label: '操作备注',
        prop: 'remark',
        valueType: 'copy',
    },
] as const

// 修改成长值
export const editGrowthColumns: PlusColumn[] = [
    {
        fieldProps: { disabled: true },
        label: '当前成长值',
        prop: 'accumulatedGrowthValue',
        valueType: 'copy',
    },
    {
        fieldProps: { precision: 0 },
        label: '数量',
        prop: 'operationGrowthValue',
        valueType: 'input-number',
    },
    {
        label: '操作备注',
        prop: 'remark',
        valueType: 'copy',
    },
] as const

export const formType = {
    growth: 'growth',
    integral: 'integral',
} as const

export const TimeLimit = {
    1: [day().format('YYYY-MM-DD 00:00:00'), day().format('YYYY-MM-DD 23:59:59')],
    2: [day().subtract(1, 'day').format('YYYY-MM-DD 00:00:00'), day().subtract(1, 'day').format('YYYY-MM-DD 23:59:59')],
    3: [day().subtract(6, 'day').format('YYYY-MM-DD 00:00:00'), day().format('YYYY-MM-DD 23:59:59')],
    4: [day().subtract(29, 'day').format('YYYY-MM-DD 00:00:00'), day().format('YYYY-MM-DD 23:59:59')],
}
